package com.example.demo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

public class MainActivity extends AppCompatActivity {

    private WuziqiPanel wuziqiPanel;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        wuziqiPanel=findViewById(R.id.id_wuziqi);

        Timer timer=new Timer();
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                queryFromBmob();
            }
        },100,500);
    }

    private void queryFromBmob() {
        BmobQuery<WuZiData> wuZiDataBmobQuery=new BmobQuery<>();
        wuZiDataBmobQuery.addWhereEqualTo("matchId","660626");
        wuZiDataBmobQuery.findObjects(new FindListener<WuZiData>() {
            @Override
            public void done(List<WuZiData> list, BmobException e) {
                if(e==null && list!=null && list.size()>0){
                    wuziqiPanel.setDate(list.get(0));
                }
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main,menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id=item.getItemId();

        if (id==R.id.action_settings){
            wuziqiPanel.start();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
